<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录中转页</title>
</head>
<body>
  <p>中转页面！！！！！</p>
</body>
</html>

<script type="text/javascript">

  window.onload = function (){
    parseUrlTokenToLocalStore().then(() =>{

        // debugger
      //跳转至首页
      window.location.replace("/pages/index.html");
    })

  }


  /**
   * 存储token至 localstore
   * @return {Promise<unknown>}
   */
  function parseUrlTokenToLocalStore() {
    return new Promise((resolve, reject) =>{

      var token = getParam("token");
      if (token == undefined || token == "") {
        reject()
        return
      }

      localStorage.setItem("token", token);
      resolve();
    } )

  }

  /**
   * 获取指定的URL参数值
   * URL:http://www.xxx.com/index?name=123
   * 参数：param URL参数
   * 调用方法:getParam("name")
   * 返回值:123
   * alert(getParam('date'));
   */
  function getParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    //search,查询？后面的参数，并匹配正则
    var r = location.search.substr(1).match(reg);
    if (r != null) return decodeURI(decodeURI(r[2]));
  }


  /**
   * 删除url上指定参数，并发起请求
   * window.location.replace(urlDelParams('params'))
   * @param name
   * @return {string}
   */
  function urlDelParams(name) {
    var loca = window.location
    var baseUrl = loca.origin + loca.pathname + '?'
    var query = loca.search.substr(1)
    if (query.indexOf(name) > -1) {
      var obj = {}
      var arr = query.split('&')
      for (var i = 0; i < arr.length; i++) {
        arr[i] = arr[i].split('=')
        obj[arr[i][0]] = arr[i][1]
      }
      delete obj[name]
      var url =
              baseUrl +
              JSON.stringify(obj)
                      .replace(/[\"\{\}]/g, '')
                      .replace(/\:/g, '=')
                      .replace(/\,/g, '&')
      return url
    }
  }
</script>